﻿//-----------------------------------------------------------------------
// <copyright file="PostGenerateGradle.cs" company="Google">
//
// Copyright 2020 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
//-----------------------------------------------------------------------

using UnityEditor.Android;
using UnityEngine;

namespace Google.Android.PerformanceTuner.Editor
{
    #if UNITY_2018_2_OR_NEWER
    /// <summary>
    ///     PostGenerateGradle.
    ///     Only available for version 2018.2 or newer.
    ///     For previous versions tuningfork files will be saved immediately to StreamingAssets.
    /// </summary>
    public class PostGenerateGradle : IPostGenerateGradleAndroidProject
    {
        public int callbackOrder
        {
            get { return 100; }
        }

        /// <summary>
        ///     Create default fidelity messages with quality settings if default mode is enabled.
        /// </summary>
        /// <param name="path">path to android project</param>
        public void OnPostGenerateGradleAndroidProject(string path)
        {
            var setupConfig = FileUtil.LoadSetupConfig();
            if (setupConfig.pluginEnabled)
            {
                Debug.Log("Android Performance Tuner is enabled, copying files to android project...");
                FileUtil.CopyTuningforkFilesToAndroidProject(path);
                if (!setupConfig.useAdvancedFidelityParameters)
                {
                    Debug.Log("Android Performance Tuner is using default fidelity parameters, generating default quality levels...");
                    FileUtil.SaveFidelityMessagesInApk(path, MessageUtil.FidelityMessagesWithQualityLevels());
                }
            }
        }
    }
    #endif
}